//
//  YZWeakTimeTarget.m
//  kuaiyi
//
//  Created by jacoy on 16/5/7.
//
//

#import "YZWeakTimeTarget.h"

@interface YZWeakTimeTarget ()
@property (nonatomic, weak) id aTarget;
@property (nonatomic, assign) SEL aSelector;
@end

@implementation YZWeakTimeTarget
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo {
    
    YZWeakTimeTarget *target = [[YZWeakTimeTarget alloc] init];
    // 记录真实回调target
    target.aTarget = aTarget;
    target.aSelector = aSelector;
    
    return [NSTimer scheduledTimerWithTimeInterval:ti target:target selector:@selector(update:) userInfo:userInfo repeats:yesOrNo];
}

- (void)update:(NSTimer *)timer{
    //    NSLog(@"update");
    // 回调控制器的update方法
    [self.aTarget performSelector:self.aSelector withObject:timer];
    
}
@end
